#!/usr/bin/env python3
# -*- coding: utf-8 -*-

#读取projectinfolist.conf
import codecs 
import configparser
import string, os, sys

class GameInfoReader(object):
	def __init__(self,configfilepath):
		self.__configfilepath = configfilepath
		self.__projectinfodict = {}
		self.__configreader = configparser.ConfigParser()

		if(False == os.path.exists(self.__configfilepath)):
			raise Exception(self.__configfilepath + " 文件不存在,初始化失败!")
		
		fp = codecs.open(self.__configfilepath, "rb", "utf-8")
		self.__configreader.readfp(fp)
		#self.__configreader.read(self.__configfilepath)	// 不支持utf-8
		secname = "gamebaseinfo"
		self.__projectinfodict["app_original_path"] = self.__configreader.get(secname,"app_original_path").replace("\\","/")
		self.__projectinfodict["versionCode"] = self.__configreader.get(secname,"versionCode")
		self.__projectinfodict["versionName"] = self.__configreader.get(secname,"versionName")
		self.__projectinfodict["packageName"] = self.__configreader.get(secname,"packageName")
		self.__projectinfodict["wozipfilepath"] = self.__configreader.get(secname,"wozipfilepath").replace("\\","/")
		self.__projectinfodict["android_tools_dir"] = self.__configreader.get(secname,"android_tools_dir").replace("\\","/")
		self.__projectinfodict["app_copy_path"] = self.__configreader.get(secname,"app_copy_path").replace("\\","/")
		self.__projectinfodict["sgand_project_path"] = self.__configreader.get(secname,"sgand_project_path").replace("\\","/")
		self.__projectinfodict["four_project_path"] = self.__configreader.get(secname,"four_project_path").replace("\\","/")
		self.__projectinfodict["weixin_project_path"] = self.__configreader.get(secname,"weixin_project_path").replace("\\","/")
		self.__projectinfodict["soulgame_appkey"] = self.__configreader.get(secname,"soulgame_appkey").replace("\\","/")

	def getOneProjectInfo(self,name):
		return self.__projectinfodict[name]

if __name__=="__main__":
	proinfoRd = GameInfoReader("./userconfig/gameinfo.conf")

	print(proinfoRd.getOneProjectInfo("app_original_path"))
	print(proinfoRd.getOneProjectInfo("versionCode"))
	print(proinfoRd.getOneProjectInfo("versionName"))
	print(proinfoRd.getOneProjectInfo("packageName"))
	print(proinfoRd.getOneProjectInfo("wozipfilepath"))
	print(proinfoRd.getOneProjectInfo("android_tools_dir"))
	print(proinfoRd.getOneProjectInfo("app_copy_path"))
	print(proinfoRd.getOneProjectInfo("sgand_project_path"))
	print(proinfoRd.getOneProjectInfo("four_project_path"))
	print(proinfoRd.getOneProjectInfo("weixin_project_path"))
	print(proinfoRd.getOneProjectInfo("soulgame_appkey"))